package cn.iocoder.yudao.module.design.asyncworker.flowTask;

import com.tlcsdm.async.executor.Async;
import com.tlcsdm.async.executor.timer.SystemClock;
import com.tlcsdm.async.wrapper.WorkerWrapper;

import java.util.concurrent.ExecutionException;

/**
 * @author Annie
 * @ClassName WorkerTest
 * @description: TODO
 * @date 2023年07月29日
 * @version: 1.0
 */
public class WorkerTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FlowTaskNotifyWorker w = new FlowTaskNotifyWorker();
        FlowTaskCreateWorker w1 = new FlowTaskCreateWorker();

        WorkerWrapper<String, String> workerWrapper1 =  new WorkerWrapper.Builder<String, String>()
                .worker(w1)
                .callback(w1)
                .param("1")
                .build();

        WorkerWrapper<String, String> workerWrapper =  new WorkerWrapper.Builder<String, String>()
                .worker(w)
                .callback(w)
                .param("0")
                .build();
        long now = SystemClock.now();
        System.out.println("begin-" + now);

        Async.beginWork(100, workerWrapper, workerWrapper1);
//        Async.beginWork(800, workerWrapper, workerWrapper1, workerWrapper2);
//        Async.beginWork(1000, workerWrapper, workerWrapper1, workerWrapper2);

        System.out.println("end-" + SystemClock.now());
        System.err.println("cost-" + (SystemClock.now() - now));
        System.out.println(Async.getThreadCount());

        System.out.println(workerWrapper.getWorkResult());
        Async.shutDown();
    }
}
